<?php
/**
 * Created by PhpStorm.
 * User: SCKJ
 * Date: 16/1/9
 * Time: 下午5:40
 */
namespace Utils;

use GatewayWorker\Lib\Gateway;

class ErrorMsg {

    private $err_arr;

    public function __construct($message,$requestId,$ope,$type)
    {
        $this->err_arr = array();

        //event
        $this->err_arr[EVENT] = EVENT_ERR_MSG;

        //data
        $data = array();
        $data[MESSAGE] = $message;
        $data[OPERATION] = $ope;
        $data[TYPE] = $type;
        $this->err_arr[DATA] = $data;
        $this->err_arr[REQUEST_ID] = $requestId;
    }

    public static function sendErr($message,$requestId = '0',$ope = 'normal',$type = ERR_TYPE_NOTICE)
    {
        $body = new ErrorMsg($message,$requestId,$ope,$type);
        $body->send();
        return null;
    }

    public function send()
    {
        Gateway::sendToCurrentClient(json_encode($this->err_arr));
    }
}